/*******************************************************************************
 * Copyright (c) 2006 Ultimate Technology, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Bojan Vukojevic - initial API and implementation
 *     Nick Panin - adopting for modern Java && Eclipse
 *******************************************************************************/
package com.ultimatetech.cim.graphical;


import javax.wbem.cim.CIMClass;

import org.eclipse.draw2d.AbstractBorder;
import org.eclipse.draw2d.Clickable;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Control;


public class UMLCIMClass extends Clickable {
	
	private CIMClass cc = null;
	
	public class CompartmentFigure extends Figure {
		public CompartmentFigure() {
			ToolbarLayout layout = new ToolbarLayout();
			layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
			layout.setStretchMinorAxis(false);
			layout.setSpacing(2);
			setLayoutManager(layout);
			setBorder(new CompartmentFigureBorder());			
		}

		public class CompartmentFigureBorder extends AbstractBorder {
			public Insets getInsets(IFigure figure) {
				return new Insets(1, 0, 0, 0);
			}

			public void paint(IFigure figure, Graphics graphics, Insets insets) {
				graphics.drawLine(getPaintRectangle(figure, insets)
						.getTopLeft(), tempRect.getTopRight());
			}
		}
	}

	  public static Color classColor = new Color(null,255,255,206);
	  private CompartmentFigure attributeFigure = new CompartmentFigure();
	  private CompartmentFigure methodFigure = new CompartmentFigure();
	  
	  public UMLCIMClass(Label name, Color color, CIMClass c, Control control) {
		  if(color == null){
			  color = classColor;
		  }
	    ToolbarLayout layout = new ToolbarLayout();
	    setLayoutManager(layout);	
	    setBorder(new LineBorder(ColorConstants.black,1));
	    setBackgroundColor(color);
	    setOpaque(true);
	    cc = c;
	    add(name);	
	    add(attributeFigure);
	    add(methodFigure);
	    //name.setToolTip(new Label("this is tooltip"));
	    //name.addMouseMotionListener(new PersistentToolTipListener(name, "This is tooltip", control));
	    addMouseListener(new UMLCIMClassMouseListener(cc));
	  }
	  public UMLCIMClass(Label name, CIMClass c) {
		  this(name, classColor, c, null);		 		  		 
	  }
	  
	  public CompartmentFigure getAttributesCompartment() {
	    return attributeFigure;
	  }
	  public CompartmentFigure getMethodsCompartment() {
	    return methodFigure;
	  }
	  
	  /**
	 * @return Returns the cc.
	 */
	public CIMClass getCIMClass() {
		return cc;
	}

}
